var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

Page({
  data: {
    orderList: [],
    showType: 0
  },
  onLoad: function (options) {},

  onPullDownRefresh() {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.getOrderList();
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },

  getOrderList() {
    let that = this;
    util.request(api.GroupOnMy, {
      showType: that.data.showType
    }).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          orderList: res.data.data,
          count: res.data.count,
          showType: that.data.showType
        });
      }
    });
  },
  switchTab: function (event) {
    let showType = event.currentTarget.dataset.index;
    this.setData({
      showType: showType
    });
    this.getOrderList();
  },

  onShareAppMessage: (res) => {
    var shareMsg = "";
    var sharepath = "";
    var gId, ruleId;
    if (res.from === 'button') {
      console.log("--转发按钮");
      shareMsg = "一起来拼团," + res.target.dataset.gname;
      var arrs = res.target.id.split(",");
      gId = arrs[0];
      ruleId = arrs[1];
      sharepath = '/pages/goods/goods?id=' + gId + '&ruleId=' + ruleId
    } else {
      console.log("--右上角菜单");
      shareMsg = "一起来拼团,还剩几个位置";
      sharepath = '/pages/index/index'
    }
    return {
      title: shareMsg,
      path: sharepath
    }
  },
  onReady: function () {},
  onShow: function () {
    this.getOrderList();
  },
  onHide: function () {},
  onUnload: function () {}
})